import com.lfl.spring6.bean.User;
import com.lfl.spring6.service.CustomerService;
import com.lfl.spring6.service.OrderService;
import com.lfl.spring6.service.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class test {
    @Test
    public void test1() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
        UserService userService = (UserService) ctx.getBean("userServiceBean");
        userService.saveUser();
    }

    @Test
    public void test2() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
        CustomerService customerService = (CustomerService) ctx.getBean("csBean");
        customerService.save();
    }

    @Test
    public void test3() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("set-di.xml");
        //外部bean测试
        OrderService orderService = (OrderService) ctx.getBean("orderServiceBean");
        orderService.generate();
        System.out.println("-------------------------------------------------------------------------------");
        //内部bean测试
        OrderService orderService2 = (OrderService) ctx.getBean("orderServiceBean2");
        orderService2.generate();

    }

    @Test
    public void TestUserEasy(){
        ApplicationContext ctx =new ClassPathXmlApplicationContext("set-di.xml");
        User user = (User) ctx.getBean("userBean");
        System.out.println(user);
    }
}
